package com.woniuxy.microsysserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.microsysserver.entity.FortuneCarEntity;
import com.woniuxy.microsysserver.entity.FortuneHeadlinesEntity;
import com.woniuxy.microsysserver.service.FortuneCarService;
import com.woniuxy.microsysserver.service.FortuneHeadlinesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Auther: wuson  <br/>
 * Date: 2021/4/12:17:16  <br/>
 * Description:
 */
@RefreshScope
@Api("财富直通车")
@Slf4j
@RequestMapping("/sys/fortunecar")
@RestController
public class FortuneCarController {

    @Autowired(required = false)
    private FortuneCarService fortuneCarService;

    @ApiOperation("财富直通车信息")
    @PostMapping(value = "/info",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean getInfo(){
        List<FortuneCarEntity> fortuneCarEntities = fortuneCarService.selectAll();
        for (FortuneCarEntity fortuneCarEntity : fortuneCarEntities) {
            Date activityTime = fortuneCarEntity.getActivityTime();
            Date endTime = fortuneCarEntity.getEndTime();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM月dd日");
            String start = simpleDateFormat.format(activityTime);
            String end = simpleDateFormat.format(endTime);
            fortuneCarEntity.setStartToEnd(start+"-"+end);
        }
        return ResultBean.builder().code(200).data(fortuneCarEntities).build();
    }
}
